import time
# 用户数据
information1={"username":"admin","password":"123","name":"管理员"}
information2={"username":"Monica","password":"123456","name":"莫尼卡"}
information3={"username":"Kelly","password":"123456","name":"凯利"}
information4={"username":"Laura","password":"123456","name":"劳拉"}
information5={"username":"Irene","password":"123456","name":"艾琳"}
information6={"username":"Alice","password":"123456","name":"艾丽丝"}
# 商品数据
goods1={"No":"1","goods_name":"牙膏","price":8.0,"discount":8.7}
goods2={"No":"2","goods_name":"水杯","price":3.0,"discount":9.7}
goods3={"No":"3","goods_name":"毛巾","price":10.0,"discount":7.9}
goods4={"No":"4","goods_name":"牙刷","price":8.0,"discount":9.7}
goods5={"No":"5","goods_name":"纸巾","price":20.0,"discount":8.7}
# 初始化变量
informations_list=[information1,information2,information3,information4,information5]
goods_list=[goods1,goods2,goods3,goods4,goods5]
operations={1:"显示商品列表",2:"增加商品",3:"删除商品",4:"设置折扣",5:"修改价格",6:"按价格排序（升序、降序）",7:"退出"}
tag=0
del_tag=0
user_information={}
while True:
    # 输入用户名密码
    username=input("用户名：")
    pwd=input("密码：")
    # 验证
    for information in informations_list:
        if username==information.get("username") and pwd==information.get("password"):
            user_information=information
            tag=1
            break
    if tag==1:
    # 登录成功
        while True:
            print("系统首页".center(30, '='))  # 显示系统首页
            # 显示操作菜单
            print("操作选项：")
            for key, value in operations.items():
                print(f'{key}：{value}')
            option=input("请输入选项序号：")
            if option=="1":
                # 显示商品列表
                print("商品列表：")
                print("编号   名称   价格   折扣")
                for goods in goods_list:
                    print(tuple(goods.values()))
                time.sleep(1)
            elif option == "2":
                add_goods={}
                goods1={"No":"1","goods_name":"牙膏","price":8.0,"discount":8.7}
                add_goods.update(No=str(len(goods_list)+1))
                add_goods.update(goods_name=input("请输入增加商品的名称："))
                add_goods.update(price=float(input("请输入增加商品的价格：")))
                add_goods.update(discount=float(input("请输入增加商品的折扣：")))
                goods_list.append(add_goods)
                print("商品新增成功！！！")
            elif option == "3":
                del_goods_No=input("请输入要删除商品的编号")
                for del_goods in goods_list:
                    if del_goods_No== del_goods["No"]:
                        del_tag=1
                        no=int(del_goods_No)
                        goods_list.pop(no-1)
                        break
                if del_tag==1:
                    print("删除成功！！！")
                    del_tag=0
                else:
                    print("输入的编号不存在，请重新操作！！！")
            elif option == "4":
                discount_goods_No = input("请输入设置折扣的商品编号：")
                discount_tag=0
                for discount_goods in goods_list:
                    if discount_goods_No == discount_goods["No"]:
                        discount_tag = 1
                        discount_goods["discount"] = float(input("请输入折扣："))
                        break
                if discount_tag == 1:
                    print("折扣设置成功！！！")
                    discount_tag = 0
                else:
                    print("输入的编号不存在，请重新操作！！！")
            elif option == "5":
                price_goods_No = input("请输入修改价格的商品编号：")
                for price_goods in goods_list:
                    if price_goods_No == price_goods["No"]:
                        price_tag = 1
                        price_goods["price"] = float(input("请输入修改后的价格："))
                        break
                if price_tag == 1:
                    print("价格修改成功！！！")
                    price_tag = 0
                else:
                    print("输入的编号不存在，请重新操作！！！")
            elif option == "6":
                for i in range(len(goods_list) - 1):
                    for j in range(len(goods_list) - 1 - i):
                        if goods_list[j].get("price") > goods_list[j + 1].get("price"):
                            tamp = goods_list[j]
                            goods_list[j] = goods_list[j + 1]
                            goods_list[j + 1] = tamp
                sort_option=input("请输入按价格排序方式（1-升序，任意键-降序）：")
                if sort_option=="1":
                    continue
                else:
                    goods_list.reverse()
            elif option == "7":
                tag=0
                print("退出成功！！！")
                break
            else:
                print("操作选项序号输入错误，请重新输入！")
                continue



    else:
    # 登录失败
        print("登录失败")



